<template>
  <div>
    <BasicTable @register="registerTable" :rowSelection="rowSelection">
      <template #toolbar>
        <a-button type="primary" @click="handleAppointmentOpt(selectedRow)" :disabled="!hasSelectedRows || selectedRow.appointmentState != 1" v-auth="'ACTION_guibintingyuyueCheck'">预约操作 </a-button>
        <a-button type="primary" @click="handleLookOrder(selectedRow)" :disabled="!hasSelectedRows || selectedRow.sourceType == 2" v-auth="'ACTION_guibintingyuyueLookOrder'"> 查看订单 </a-button>
      </template>
      <template #action="{ record }">
        <TableAction :actions="getTableAction(record)" />
      </template>
    </BasicTable>
    <AppointmentDetailModal @register="registerAppointmentDetailModal"></AppointmentDetailModal>
    <AppointmentOptModal @register="registerAppointmentOptModal" @success="handleSuccess"></AppointmentOptModal>
    <OrderDetailModal @register="registerOrderDetailModal"></OrderDetailModal>
  </div>
</template>
<script lang="ts" setup name="guibintingyuyue">
import { ActionItem, BasicTable, TableAction } from '@apps/antd-admin/src/components/Table';
import { useBaseTable } from '@apps/antd-admin/src/hooks';
import { Api } from './data/api';
import { columns, searchFormSchema } from './data/data';
import { useMessage } from '@apps/antd-admin/src/hooks/web/useMessage';
import { useModal } from '@apps/antd-admin/src/components/modal';
import AppointmentDetailModal from './components/AppointmentDetailModal.vue';
import AppointmentOptModal from './components/AppointmentOptModal.vue';
import OrderDetailModal from '@apps/ant-bus/src/views/business/financialManage/order/OrderDetailModal.vue';

const { createMessage } = useMessage();
const { prefixCls, tableContext, handleSuccess } = useBaseTable({
  designScope: 'appointment-template',
  tableProps: {
    //表格标题
    title: '贵宾厅预约列表',
    //主键字段
    rowKey: 'appointmentId',
    //列表接口
    listUrl: Api.page,
    //删除接口
    delUrl: Api.remove,
    //列定义
    columns,
    //查询表单配置
    formConfig: {
      labelWidth: 120,
      showExportButton: true,
      exportButtonOptions: {
        code: 'guibintingyuyueExport',
      },
      schemas: searchFormSchema,
    },
    //操作列配置
    actionColumn: {
      width: 100,
      title: '操作',
      dataIndex: 'action',
      slots: { customRender: 'action' },
      fixed: 'right',
    },
    clickToRowSelect: true,
    rowSelection: {
      type: 'radio',
    },
    searchInfo: { appointType: 1 },
  },
});

//注册table数据
const [registerTable, { reload }, { rowSelection, selectedRow, hasSelectedRows }] = tableContext;

const [registerAppointmentDetailModal, { openModal: openAppointmentDetailModal }] = useModal();
const [registerAppointmentOptModal, { openModal: openAppointmentOptModal }] = useModal();
const [registerOrderDetailModal, { openModal: openOrderDetailModal }] = useModal();

/**
 * 行内操作栏
 */
function getTableAction(record): ActionItem[] {
  return [
    {
      label: '查看详情',
      onClick: handleLookAppointmentDetail.bind(null, record),
    },
  ];
}

function handleLookAppointmentDetail(record) {
  openAppointmentDetailModal(true, {
    record,
    isUpdate: false,
  });
}

function handleAppointmentOpt(record) {
  openAppointmentOptModal(true, {
    record,
    isUpdate: false,
  });
}

function handleLookOrder(record) {
  openOrderDetailModal(true, {
    record,
    isUpdate: false,
  });
}
</script>
